﻿using CardMonitor.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CardMonitor.Windows
{
    /// <summary>
    /// StatementWindow.xaml 的交互逻辑
    /// </summary>
    public partial class StatementWindow : Window
    {
        ImageBrush imageBrush;
        SynchronizationContext _syncContext = null;
        BillModel billModel = null;

        String message = null;
   

        public StatementWindow()
        {
            
            InitializeComponent();
           
            message = App.getConfig().statementMessage;
            _syncContext = SynchronizationContext.Current;

            this.Loaded += Winndow_Loaded;
           

        }

        private void Winndow_Loaded(object sender, RoutedEventArgs e)
        {
            txtMessage.Text = message;
         
        }
        public void setPersonImage(ImageBrush image)//获取身份证照片
        {
            signingDate.Text = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss");//签订日期时间
            this.imageBrush = image;
            this.cardImagePanel.Background = image;
            //System.Drawing.Image bmp = image; // 自己初始化的有效的 image
            //System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
            //bi.BeginInit();
            //bi.StreamSource = new MemoryStream(ms.ToArray()); // 不要直接使用 ms
            //bi.EndInit();
            //cardImage.Source = bi; // done!
            //ms.Close();

            //System.Drawing.Image bmp = image; // 自己初始化的有效的 image
            //System.Windows.Media.Imaging.BitmapSource bi =
            //System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
            //bmp.GetHbitmap(),
            //IntPtr.Zero,
            //Int32Rect.Empty,
            //BitmapSizeOptions.FromEmptyOptions());
            // 上面以 bmp 格式为例的,其他格式自处理
            //this.cardImage.Source = bi; // Done!
            //this.image = image;
            //this.cardImage.Source= BitmapFrame.Create(image, BitmapCreateOptions.None, BitmapCacheOption.Default);;
        }
        public void setBillModel(BillModel billModel)//获取对象值
        {
            this.billModel = billModel;
            this.DataContext = billModel;

        }

        private void closeWindow(object sender, RoutedEventArgs e)
        {
            //容器Grid
            Grid grid = this.Owner.Content as Grid;
            //父级窗体原来的内容
            UIElement original = VisualTreeHelper.GetChild(grid, 0) as UIElement;
            //将父级窗体原来的内容在容器Grid中移除
            grid.Children.Remove(original);
            //赋给父级窗体
            this.Owner.Content = original;
            this.DialogResult = false;
            this.Close();
        }

        private void click_agreee(object sender, RoutedEventArgs e)
        {
            Grid grid = this.Owner.Content as Grid;
            //父级窗体原来的内容
            UIElement original = VisualTreeHelper.GetChild(grid, 0) as UIElement;
            //将父级窗体原来的内容在容器Grid中移除
            grid.Children.Remove(original);
            //赋给父级窗体
            this.Owner.Content = original;
            this.DialogResult=true;
            this.Close();
        }

        private void changeButtonEnable(object sender, RoutedEventArgs e)
        {
            agreeButton.IsEnabled = true;
        }

        private void changeButtonUnenable(object sender, RoutedEventArgs e)
        {
            agreeButton.IsEnabled = false;

        }
        
    }
}
